﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;

namespace WcfService
{
    public interface IWCFServiceCallBack
    {
        [OperationContract(IsOneWay = true)]
        void SayHelloCallBack();
    }

    [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IWCFServiceCallBack))]
    public interface IWCFServiceCB
    {
        [OperationContract]
        string SayHelloToUser(string userName);
    }
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    public class WCFServiceCB : IWCFServiceCB
    {
        IWCFServiceCallBack callback = OperationContext.Current.GetCallbackChannel<IWCFServiceCallBack>();

        #region IWCFServiceCB 成员

        public string SayHelloToUser(string userName)
        {
            Console.WriteLine("SayHelloToUser Call :{0}", userName);
            System.Threading.Thread m_Thread = new System.Threading.Thread(CallBack);
            m_Thread.Start();
            m_Thread.Abort();
            return "Hello " + userName;
        }

        public  void CallBack()
        {
            callback.SayHelloCallBack();
        }

        #endregion
    }
}
